{% extends "default.html" %}
{% block title %}专卖店管理 - {{ mystore.name }}{% endblock %}

{% block pagecss %}
html{padding:0 !important;padding:32px 0 35px;}
.navi{width:100%;height:28px;border-bottom:1px solid #d6d6d6;box-shadow:0 0 3px #a6a6a6;position:fixed;top:0;left:0;right:0;background:#e3e3e3;background:linear-gradient(top,#fbfbfb,#e3e3e3);background:-o-linear-gradient(top,#fbfbfb,#e3e3e3);background:-ms-linear-gradient(top,#fbfbfb,#e3e3e3);background:-moz-linear-gradient(top,#fbfbfb,#e3e3e3);background:-webkit-linear-gradient(top,#fbfbfb,#e3e3e3);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fbfbfb',endColorstr='#e3e3e3',GradientType=0);}
.tool{width:100%;height:27px;line-height:30px;border-top:1px solid transparent;border-bottom:1px solid #d3d3d3;box-shadow:2px 1px 2px #a6a6a6;background:#e2e2e2;background:linear-gradient(top,#f8f8f8,#e2e2e2);background:-o-linear-gradient(top,#f8f8f8,#e2e2e2);background:-ms-linear-gradient(top,#f8f8f8,#e2e2e2);background:-moz-linear-gradient(top,#f8f8f8,#e2e2e2);background:-webkit-linear-gradient(top,#f8f8f8,#e2e2e2);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f8f8f8',endColorstr='#e2e2e2',GradientType=0);}
.cont{height:auto !important;height:100%;position:absolute;top:32px;bottom:0;left:0;right:0;width:100%;border:0;overflow:auto;}
.detl{float:left;width:100%;border:0;height:100%;}
.detl .listnav{height:100%;width:100%;float:left;margin:0;}
.itab{height:100%;}
.itab .on{height:100%;}
.none{width:100%;text-align:center;}
.f14{font-size:14px;line-height:1.7em;padding:5px 15px;} .f14 *{font-size:large;}
{% endblock %}

{% block content %}
<!-- powered by:{{ app_id }} -->
{% endblock %}

{% block datas %}
<div id="salemanage" class="detl"></div>
<div id="vipmanage" class="detl"></div>
<div id="rptmanage" class="detl"></div>
<div id="pvsmanage" class="detl"></div>
<div id="pvrptmanage" class="detl">
    <div id="pvpmanage" class="detl"><form class="ifom" id="fpvterm">
    <div class="fitem" style="width:auto;clear:both;"><div class="ftitle">当前业绩周期：</div><div class="fdata"><select class="fvsel" name="pvterm"><option value='{{isotime|date:"Y-m"}}' selected='selected'>{{isotime|date:"Y-m"}}</option></select></div></div>
    <div class="fitem odd" style="clear:both;"><div id="pvautoapv" class="detl"></div></div>
    </form></div>
    <div class="detl" style="height:23px;border:solid 1px #ccd;border-width:1px 0;line-height:23px;background:#ffb;"><img src="{{ imgsurl }}/icos/isignify.gif" style="width:16px;height:16px;padding:0 5px 4px 2px;"><span style="color:#161;font-weight:bold;">a. 在下面可报单业绩中选定要报单的业绩项并确认。 或者 b. 确认所有可报单项。</span></div>
    <div id="spvmanage" class="detl"></div>
</div>
<div id="pomanage" class="detl"></div>
<div id="stockgz" class="detl"></div>
<div id="msgdata" style="width:200px;height:30px;" class="ta-c"><div id="msgdatatext">发送数据中....</div><div class="iloading"><div class="ianim"></div></div></div>
<div id="vipsel" class="detl" style="height:586px;"></div>
<div id="popvipsel" class="detl" style="height:586px;"></div>
<div id="prodsel" class="detl" style="height:586px;"></div>
<div id="poprodsel" class="detl" style="height:586px;"></div>
{% endblock %}

{% block jscript %}
var data = {
    pvtype:{ {% if pvtypes %}{% for pvt in pvtypes %}'{{ pvt.key }}':{'guid':'{{ pvt.key }}', 'ptcode':'{{ pvt.code }}', 'ptname':'{{ pvt.name }}', 'ratepv':'{{ pvt.ratepv }}', 'pvrate':'{{ pvt.pvrate }}', 'bvrate':'{{ pvt.bvrate }}', 'locked':'{% if pvt.locked %}yes{% else %}no{% endif %}', 'lockin':'{% if pvt.locked %}不可用{% else %}可用{% endif %}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %} },
    prodclass:{ {% if pclass %}{% for pcls in pclass %}'{{ pcls.key }}':{'guid':'{{ pcls.key }}', 'clscode':'{{ pcls.code }}', 'clsname':'{{ pcls.name }}', 'refcls':'{{ pcls.refcls.key }}', 'refclscode':'{% if pcls.refcls %}{{ pcls.refcls.code }}{% else %}无{% endif %}', 'clscss':'{{ pcls.csstyle }}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %} },
    stocks:{  },
    optbcmpny:{ {% if optcmpny %}{% for cbcs in optcmpny %}'{{ cbcs.key }}':{'guid':'{{ cbcs.key }}', 'acode':'{{ cbcs.code }}', 'aname':'{{ cbcs.name }}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %} },
    optastore:{ {% if optstore %}{% for aacs in optstore %}'{{ aacs.key }}':{'guid':'{{ aacs.key }}', 'acode':'{{ aacs.code }}', 'aname':'{{ aacs.name }}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %} },
    optguid:{},
    optvips:{},
    optprods:{},
    ssbill:{ {% if ssbill %}{% for ss in ssbill %}'{{ ss.key }}':{'guid':'{{ ss.key }}', 'vipln':'{{ ss.vip.lastname }}', 'vipfn':'{{ ss.vip.firstname }}', 'vipname':'{{ ss.vip.lastname }}{{ ss.vip.firstname }}', 'vipid':'{{ ss.vip.idcard }}', 'date':'{{ ss.date|date:"Y-m-d" }}', 'prod':'{{ ss.prod.key }}', 'prodname':'{{ss.prod.name}}', 'price':'{{ss.price}}', 'qty':'{{ss.qty}}', 'amount':'{{ss.amount}}', 'pv':'{{ss.pv}}', 'bv':'{{ss.bv}}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %} },
    salesbill:{},
    pvrptbill:{}
};
var my = {
    store : { {% if mystore %}'guid':'{{ mystore.key }}','aname':'{{ mystore.name }}', 'addr':'{{ mystore.addr }}', 'postcode':'{{ mystore.postcode }}', 'phone':'{{ mystore.phone }}', 'mobile':'{{ mystore.mobile }}'{% endif %} }
};
var fres = {
    vips:[
        {'type':'select', 'name':'refcomp', 'label':'公司/分公司：', text:'请选择...', value:'', opts: function(){return getopts(data.optbcmpny,'guid','aname');}},
        {'type':'select', 'name':'refstore', 'label':'授权经销店：', text:'请选择...', value:'', opts: function(){return getopts(data.optastore,'guid','aname');}},
        {'type':'icalendar', 'name':'jdate', 'label':'加入日期', tips:'如当月报单已结束，请选下一月份', readonly:1},
        {'type':'iselect', 'name':'refvip', 'textname':'refvipid', 'label':'老顾客：', topopt:[{text:'请选择...', value:''}], readonly:1, optwidth:206, seltype:'pop', pop:'vipsel', opts:function(){return getopts(data.optvips, 'guid', 'refvipid', 'vipname');}, fontcase:'upper'},
        {'type':'text', 'name':'idcard', 'label':'顾客的身份证号码：', autofocus:1, tips:'顾客自己的15或18位身份证号码', fontcase:'upper', valid:'type:idcard;adv:请输入正确的身份证号码;'},
        {'type':'text', 'name':'uname', 'label':'姓名：', placeholder:'顾客姓名', valid:'type:str;adv:请输入姓名'},
        {'type':'radio', 'name':'gender', 'label':'男', value:'yes', text:'性别'},
        {'type':'radio', 'name':'gender', 'label':'女', value:'no', checked:1},
        {'type':'text', 'name':'vipcard', 'label':'卓越卡号码：'},
        {'type':'text', 'name':'vipcardsn', 'label':'卓越卡背面SN：', placeholder:'如：8888-8888-8888'},
        {'type':'text', 'name':'phone', 'label':'电话号码：'},
        {'type':'text', 'name':'mobile', 'label':'手机号码：'}
        ],
    pvpv:[
        {'type':'iselect', 'name':'vip', 'textname':'vipid', 'label':'顾客/业务员：', readonly:1, valid:'type:str;adv:顾客/业务员不能为空', optwidth:206, seltype:'pop', pop:'popvipsel', opts:function(){return getopts(data.optvips, 'guid', 'vipid', 'vipname');}, fontcase:'upper', onchange: function(){if(this.value){setForm(data.optguid[this.value], this.form, {name:['guid']});}} },
        {'type':'text', name:'vipname', label:'顾客姓名：', placeholder:'选择顾客/业务员后自动显示', readonly:1},
        {'type':'select', 'name':'pvtype', 'label':'PVBV类型：', 'text':'请选择 ....', value:'', opts: function(){return getopts(data.pvtype,'guid','ptname');}, valid:'type:str;adv:请选择PVBV类型'},
        {'type':'text', name:'amount', label:'金额：', autofocus:1, valid:'type:price;adv:请输入金额'}
        ],
    pvpm:[
        {'type':'text', 'name':'vipid', 'label':'顾客/业务员：', readonly:1 },
        {'type':'text', name:'vipname', label:'顾客姓名：', placeholder:'选择顾客/业务员后自动显示', readonly:1},
        {'type':'select', 'name':'pvtype', 'label':'PVBV类型：', 'text':'请选择 ....', value:'', opts: function(){return getopts(data.pvtype,'guid','ptname');}, valid:'type:str;adv:请选择PVBV类型'},
        {'type':'text', name:'amount', label:'金额：', autofocus:1, valid:'type:price;adv:请输入金额'},
        {'type':'hidden', 'name':'vip', value:''}
        ],
    pvrpt:[
        {'type':'icalendar', 'name':'date', 'label':'业绩周期：', readonly:1, valid:'type:str;adv:日期不能为空'},
        {'type':'igrid', 'name':'pvs', 'label':'业绩明细：', valid:'type:multi;adv:业绩明细不能为空', grid:[{cls:'px140',text:'编号',col:'vipid'}, {cls:'px50',text:'姓名',col:'vipname'}, {cls:'px160',text:'PV类型',col:'pvtype'}, {cls:'px70 t-r',text:'金额',col:'amount'}, {cls:'px70 t-r',text:'净额PV',col:'pv'}],
            sum:{col:['amount','pv']},
            tool:{ add:{label:'添加',fn:function(fn){ var _fn = typeof fn=='function'? fn:function(){};popmod({add:'pvpv',title:'报单业绩项', 'fn': {onsubmit:function(){this.amount.value=this.price.value*this.qty.value;var ret={};ret[this['prod'].value]=jsonForm(this);_fn(ret);popform.form.reset();return false;}}});}},
                mod:{label:'修改',fn:function(fn, mk){ var _fn = typeof fn=='function'? fn:function(){};popmod({add:'pvpm',title:'报单业绩项', mod:mk, 'fn': {onsubmit:function(){this.amount.value=this.price.value*this.qty.value;var ret={};ret[this['guid'].value]=jsonForm(this);_fn(ret);poptop.hide();return false;}}});}},
                del:{label:'删除',fn:function(fn){}}},
            data:function(){return data.pvrptbill;}}
        ],
    ssbillp:[
        {'type':'iselect', 'name':'prod', 'textname':'pcode', textvalue:'title', 'label':'产品：', tips:'产品编码', valid:'type:str;adv:产品不能为空', readonly:1, optwidth:330,titlewidth:80, seltype:'pop', pop:'poprodsel', opts:function(){return getopts(data.optprods, 'guid', 'pname', 'pcode');}, fontcase:'upper', onchange: function(){if(this.value){setForm(data.optguid[this.value], this.form, {name:['guid']});}}},
        {'type':'text', name:'pname', label:'产品名称：', readonly:1},
        {'type':'text', name:'unit', label:'单位：', readonly:1},
        {'type':'text', name:'price', label:'单价：', readonly:1},
        {'type':'text', 'name':'qty', 'label':'数量：', autofocus:1, valid:'type:nz;adv:请输入大于0的整数'},
        {'type':'hidden', 'name':'amount',value:''}
        ],
    ssbpm:[
        {'type':'text', 'name':'pcode', 'label':'产品编码：', readonly:1, valid:'type:str;adv:产品不能为空', fontcase:'upper'},
        {'type':'hidden', name:'prod', value:''},
        {'type':'hidden', 'name':'amount',value:''},
        {'type':'text', name:'pname', label:'产品名称：', readonly:1},
        {'type':'text', name:'unit', label:'单位：', readonly:1},
        {'type':'text', name:'price', label:'单价：', readonly:1},
        {'type':'text', 'name':'qty', 'label':'数量：', autofocus:1, tips:'数量可以修改', valid:'type:nz;adv:请输入大于0的整数'}
        ],
    ssbill:[
        {'type':'icalendar', 'name':'date', 'label':'购货日期：', readonly:1, valid:'type:str;adv:日期不能为空'},
        {'type':'iselect', 'name':'vip', 'textname':'vipid', 'label':'顾客/业务员：', readonly:1, valid:'type:str;adv:顾客/业务员不能为空', optwidth:206, seltype:'pop', pop:'vipsel', opts:function(){return getopts(data.optvips, 'guid', 'vipid', 'vipname');}, fontcase:'upper', onchange: function(){if(this.value){setForm(data.optguid[this.value], this.form, {name:['guid']});}} },
        {'type':'text', name:'vipname', label:'顾客姓名：', placeholder:'选择顾客/业务员后自动显示', readonly:1},
        {'type':'igrid', 'name':'prod', 'label':'产品：', valid:'type:multi;adv:产品不能为空', grid:[{cls:'px80',text:'编码',col:'pcode'}, {cls:'px220',text:'名称',col:'pname'}, {cls:'px30 ta-c',text:'单位',col:'unit'}, {cls:'px60 t-r',text:'单价',col:'price'}, {cls:'px50 t-r',text:'数量',col:'qty'}, {cls:'px70 ta-r',text:'金额',col:'amount'}],
            sum:{col:['qty','amount']},
            tool:{ add:{label:'添加',fn:function(fn){ var _fn = typeof fn=='function'? fn:function(){};popmod({add:'ssbillp',title:'销售产品项', 'fn': {onsubmit:function(){this.amount.value=this.price.value*this.qty.value;var ret={};ret[this['prod'].value]=jsonForm(this);_fn(ret);popform.form.reset();return false;}}});}},
                mod:{label:'修改',fn:function(fn, mk){ var _fn = typeof fn=='function'? fn:function(){};popmod({add:'ssbpm',title:'销售产品项', mod:mk, 'fn': {onsubmit:function(){this.amount.value=this.price.value*this.qty.value;var ret={};ret[this['guid'].value]=jsonForm(this);_fn(ret);poptop.hide();return false;}}});}},
                del:{label:'删除',fn:function(fn){}}},
            data:function(){return data.salesbill;}}
        ],
    ssbm:[
        {'type':'icalendar', 'name':'date', 'label':'购货日期：', readonly:1, valid:'type:str;adv:日期不能为空'},
        {'type':'text', name:'vipid', label:'顾客/业务员：', readonly:1, fontcase:'upper', tips:'顾客/业务员不能修改'},
        {'type':'text', name:'vipname', label:'顾客姓名：', placeholder:'选择顾客/业务员后自动显示', readonly:1},
        {'type':'igrid', 'name':'prod', 'label':'产品：', tips:'如该产品项的PV类型的PV值不足因修改所减少的PV值则该产品项不会修改', valid:'type:multi;adv:产品不能为空', grid:[{cls:'px80',text:'编码',col:'pcode'}, {cls:'px220',text:'名称',col:'pname'}, {cls:'px30 ta-c',text:'单位',col:'unit'}, {cls:'px60 ta-r',text:'单价',col:'price'}, {cls:'px50 ta-r',text:'数量',col:'qty'}, {cls:'px70 ta-r',text:'金额',col:'amount'}],
            sum:{col:['qty','amount']},
            tool:{ add:{label:'添加',fn:function(fn){ var _fn = typeof fn=='function'? fn:function(){};popmod({add:'ssbillp',title:'销售产品项', 'fn': {onsubmit:function(){this.amount.value=this.price.value*this.qty.value;var ret={};ret[this['prod'].value]=jsonForm(this);_fn(ret);popform.form.reset();return false;}}});}},
                mod:{label:'修改',fn:function(fn, mk){ var _fn = typeof fn=='function'? fn:function(){};popmod({add:'ssbpm',title:'销售产品项', mod:mk, 'fn': {onsubmit:function(){this.amount.value=this.price.value*this.qty.value;var ret={};ret[this['guid'].value]=jsonForm(this);_fn(ret);poptop.hide();return false;}}});}},
                del:{label:'删除',fn:function(fn){}}},
            data:function(){return data.salesbill;}},
        {'type':'hidden', name:'vip', value:''}
        ],
    fbtn:[{name:'action', type:'hidden', value:'addnew'}, {name:'guid', type:'hidden', value:''}, { name:'submit', type: 'submit', text:'确定', ico:'{{ imgsurl }}/icos/tick.png' }, { name:'reset', type: 'reset', text:'重置', ico:'{{ imgsurl }}/icos/arrow_undo.png' }],
    faddnew:{'action':'addnew','guid':''},fmodify:{'action':'modify'},fdelete:{'action':'delete'}
};
function oasubmit(odt, css, redo){ if(!odt || odt.uitype!='idatable'){ return false; } msgalert('提交数据中....'); var fo = oaform.form, sender = aja$({url: attr(fo, 'action'), data: jsonForm(fo)}, {uprogress:function(e){var ttl=e.total, lod=e.loaded;if(e.lengthComputable){ msgalert('提交数据中....'+ (lod/ttl*1000).int10()/10 +'%');}}, finish: function(a){ if ( /^error/i.test(a) ) { alert(a.split('!?')[1]); } else if ( /^success/i.test(a) ) { var od = !css ? a.split('!?')[1].jsonQs() : a.split('!?')[1].jsonCss(); if (hop( od, 'guid' )) { var oa = {}; oa[od.guid] = od; odt.setBody(oa).pager(); } } else { alert(a); } msgpop.hide(); if(!!redo){ oapop.hide();} else{ fo.reset(); } } }); }
var foms = {
    vips: { action:'/tiens/vip', data:fres.vips.concat(fres.fbtn), onsubmit:function(){oasubmit(dtvip); return false; } },
    pvpv: { action:'/tiens/vipspv', data:fres.pvpv.concat(fres.fbtn), onsubmit:function(){} },
    pvrpt: { action:'/tiens/pvreport', data:fres.pvrpt.concat(fres.fbtn), onsubmit:function(){oasubmit(dtrpt,1,1); return false; } },
    ssbill: { action:'/tiens/salesbill', data:fres.ssbill.concat(fres.fbtn), onsubmit:function(){oasubmit(dtssbill,1,1); return false; } },
    ssbillp: { action:'/tiens/sales', data:fres.ssbillp.concat(fres.fbtn), onsubmit:function(){ return false; }, onreset:function(){ return true; } },
    ssbm: { action:'/tiens/salesbill', data:fres.ssbm.concat(fres.fbtn), onsubmit:function(){oasubmit(dtssbill,1,1); return false; } },
    ssbpm: { action:'/tiens/sales', data:fres.ssbpm.concat(fres.fbtn), onsubmit:function(){ return false; }, onreset:function(){ return true; } }
};

function amod (opt) { var opt = ext({add:'', title:'', mod:''}, opt); if (hop(foms, opt.add)) { var tit = '新增：', ico = '{{ imgsurl }}/icos/add.png'; oaform.reset(ext(foms[opt.add], opt.fn)); if(opt.mod && typeof opt.mod=='object'){ tit = '修改：'; ico = '{{ imgsurl }}/icos/page_edit.png'; setForm(opt.mod, oaform.form); setForm(fres.fmodify, oaform.form); } else { setForm(fres.faddnew, oaform.form); } oapop.show({'data':oaform.form, 'ico':ico, 'title':tit+opt.title}); } }
function popmod (opt) { var opt = ext({add:'', title:'', mod:''}, opt); if (hop(foms, opt.add)) { var tit = '新增：', ico = '{{ imgsurl }}/icos/add.png'; popform.reset(ext(foms[opt.add], opt.fn)); if( opt.mod && typeof opt.mod=='object' ){ tit = '修改：'; ico = '{{ imgsurl }}/icos/page_edit.png'; setForm(opt.mod, popform.form); setForm(fres.fmodify, popform.form); } else { setForm(fres.faddnew, popform.form); } poptop.show({'data':popform.form, 'ico':ico, 'title':tit+opt.title}); } }
function getopts(data, value, text, title){ var opts=[]; for ( var k in data){ if (title){ opts.push({'value':data[k][value], 'text':{'title':data[k][title], 'text':data[k][text]}}); } else { opts.push({'value':data[k][value], 'text':data[k][text]}); } } return opts; }
function deldtdata( odt ){ if(!odt || odt.uitype!='idatable'){ return false; } msgalert('删除数据项目中....'); var fo = odt.form, ofo = jsonForm(fo); if(hop(ofo, 'guid')){ var sender = aja$({url:fo.action, data: ext(ofo, fres.fdelete)}, { finish: function(a){ if ( /^error/i.test(a) ) { alert(a.split('!?')[1]); } else if ( /^success/i.test(a) ) { var od = a.split('!?')[1].jsonQs(); odt.setBody(od,1).pager(); } else { alert(a); } msgpop.hide(); } }); } }
def('msgpop', 'ipop', {id: 'msgpopup', notitle:1, z:30000 });
function msgalert(t){$('msgdatatext').html(t);msgpop.show({data:$('msgdata')});}
def( 'oapop', 'ipop', {id: 'oapopup' });
def( 'pvpop', 'ipop', {id: 'pvspop', width:778, height:636, autoresize:false, z:6600 });
def( 'poptop', 'ipop', {id: 'popuptop', z:7000 });
def( 'oaform', 'iform', { id: 'oaforms', elem:'datapool', onreset:function () { if (this.action.value=='addnew'){ try{ this.elements[0].focus(); }catch(e){} return true; } oapop.hide(); } } );
def( 'popform', 'iform', { id: 'popforms', elem:'datapool', onreset:function () { if (this.action.value=='addnew'){ try{ this.elements[0].focus(); }catch(e){} return true; } } } );

def( 'dtvip', 'idatable', {id:'vipdata', elem:'vipmanage', paging:{pagesize:15}, tool:{cls:'tool', menu:[{id: 'vipadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:"amod({add:'vips', title:'顾客/业务员'});" }, { label: {txt: '-|-'} }, {id: 'vipedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtvip.form);if(hop(ofo,'guid')){amod({add:'vips', title:'顾客/业务员', mod:data.vips[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}} ]},
    filter:{action:'/tiens/vip', col:{ vip_name:'', vipid:'', jmonth: {type:'select', value:'', text:'不分先后', opts:function(){var ym=[{value:'later', text:'后▼在上'},{value:'earlier', text:'先▲在上'}],y9=now().getFullYear(),m9=now().getMonth()+1;for(var y=y9;y>2009;y--){for(var m=12;m>0;m--){ if(y==y9 && m>m9){continue;}else{var v=y+'-'+(m>9?m:'0'+m);ym.push({value:v, text:v});} }}return ym.concat([{value:'2009-12', text:'2009-12'},{value:'2009-11', text:'2009-11'},{value:'outearlier', text:'09-11之前'}]);}}}},
    title:[{cls:'px70',text:'姓名',col:'vip_name'},{cls:'px140',text:'身份证号码',col:'vipid'}, {cls:'px70',text:'加入 年-月',col:'jmonth'}, {cls:'px70',text:'老顾客',col:'refvipname'}, {cls:'px140',text:'老顾客身份证',col:'refvipid'}], data:data.vips});
def( 'dtssbill', 'idatable', {id:'saledata', elem:'salemanage', paging:{pagesize:20}, tool:{cls:'tool', menu:[{id: 'saleadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn: function(){data.salesbill={};amod({add:'ssbill', title:'售货明细单'});} }, { label: {txt: '-|-'} }, {id: 'saleedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtssbill.form);if(hop(ofo,'guid')){var key=isArray(ofo.guid)?ofo.guid[0]:ofo.guid;if(hop(data.ssbill[key], 'data')){data.salesbill=data.ssbill[key].data;amod({add:'ssbm', title:'售货明细单', mod:data.ssbill[key]});}else{msgalert('正载入售货单产品明细....');var sss=aja$({url:'/tiens/sales', method:'get', data:{json:'yes',pagesize:1000,refbill:key}},{progress:function(e){var ttl=e.total, lod=e.loaded;if(e.lengthComputable){ msgalert('正载入售货单产品明细....'+ (lod/ttl*1000).int10()/10 +'%');}}, finish:function(a){if ( /^success/i.test(a) ) {msgpop.hide();var ra = a.split('`$!`');data.salesbill=data.ssbill[key].data=JSON.parse( ra[1] );amod({add:'ssbm', title:'售货明细单', mod:data.ssbill[key]});}}});}}}}, { label: {txt: '-|-'} }, {id: 'saledel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtssbill); }} ]},
    filter:{action:'/tiens/salesbill'},
    title:[{cls:'px70',text:'日期',col:'date'}, {cls:'px80',text:'顾客/业务员',col:'vipname'}, {cls:'px140',text:'顾客编号',col:'vipid'}, {cls:'px60 ta-r',text:'购货数量',col:'bqty'}, {cls:'px60 ta-r',text:'购货金额',col:'bamount'}], data:data.ssbill});
def( 'dtcspv', 'idatable', {id:'cspvdata', elem:'pvsmanage', paging:{pagesize:12}, readonly:1, sumonly:1,
    filter:{action:'/tiens/cstorepv'}, sum:{ col:['oldbalance', 'perpo', 'persum', 'perrpt', 'balance']},
    title:[ {cls:'px200 ta-c', text:'PVBV类型', col:'pvtname'}, {cls:'px90 ta-r', text:'上期结余', col:'oldbalance'}, {cls:'px90 ta-r', text:'本期进货', col:'perpo'}, {cls:'px90 ta-r', text:'本期合计', col:'persum'}, {cls:'px90 ta-r', text:'报单', col:'perrpt'}, {cls:'px90 ta-r', text:'余额', col:'balance'}], data:data.cspvs});
def( 'dtrpt', 'idatable', {id:'rptdata', elem:'rptmanage', paging:{pagesize:12}, tool:{cls:'tool', menu:[{id: 'rptauto', ico: {src: '{{ imgsurl }}/icos/page_green.png'}, label: {txt: '从销售业绩新增'}, fn:"pvpop.show({add:'pvrpt', ico: '{{ imgsurl }}/icos/page_green.png', title:'报单', data:$('pvrptmanage')});" }, { label: {txt: '-|-'} }, {id: 'rptadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '手工新增'}, fn:"amod({add:'pvrpt', title:'报单'});" }, { label: {txt: '-|-'} }, {id: 'rptedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtrpt.form);if(hop(ofo,'guid')){amod({add:'report',title:'报单', mod:data.report[ isArray(ofo.guid)?ofo.guid[0]:ofo.guid ]});}}}, { label: {txt: '-|-'} }, {id: 'rptdel', ico: {src: '{{ imgsurl }}/icos/tick.png'}, label: {txt: '确认报单'},fn:function(){ ; }} ]},
    filter:{action:'/tiens/pvreport'},
    title:[{cls:'px70',text:'日期',col:'date'}, {cls:'px70',text:'业绩周期',col:'pvterm'}, {cls:'px70 ta-r',text:'业绩金额',col:'amount'}, {cls:'px70 ta-r',text:'净额PV',col:'pv'}, {cls:'px70 ta-r',text:'净额BV',col:'bv'}, {cls:'px60 ta-c',text:'报单状态',col:'xstatus'}], data:data.report});

def( 'dtapvd', 'idatable', {id:'apvdata', elem:'pvautoapv', paging:{pagesize:1}, readonly:1, sumonly:1,
    filter:{action:'/tiens/apvrpt'}, sum:{ col:['amount', 'pv', 'bv']},
    title:[ {cls:'px70',text:'业绩周期',col:'pvterm'}, {cls:'px70 ta-r',text:'报单金额',col:'amount'}, {cls:'px70 ta-r',text:'净额PV',col:'pv'}, {cls:'px70 ta-r',text:'净额BV',col:'bv'}], data:data.apvrs});
def( 'dtspv', 'idatable', {id:'spvdata', elem:'spvmanage', paging:{pagesize:15}, tool:{cls:'tool', menu:[ {id: 'spvapvsel', ico: {src: '{{ imgsurl }}/icos/tick.png'}, label: {txt: '确认业绩项'},fn:function(){ var ofp=jsonForm('fpvterm'); }}, { label: {txt: '-|-'} }, { label: {txt: '-|-'} }, {id: 'spvapvall', ico: {src: '{{ imgsurl }}/icos/iverified.png'}, label: {txt: '确认所有可报单项'},fn:function(){ if(confirm('确认所有可报单项后也可以在当月报单确认前打开修改。\n\n确定要确认所有可报单项吗？\n\n')){ var ofp=jsonForm('fpvterm'); var apvall=aja$({url:'/tiens/approvepvsall', data:ext(ofp, {approve:'yes', allvipspv:'yes'})},{finish:function(a){alert(a);}});} }} ]},
    filter:{action:'/tiens/vipspv'},
    title:[{cls:'px50',text:'姓名',col:'vipname'}, {cls:'px140',text:'身份证号码',col:'vipid'}, {cls:'px160',text:'PVBV类型',col:'pvtypename'}, {cls:'px70 ta-r',text:'业绩金额',col:'amount'}, {cls:'px70 ta-r',text:'净额PV',col:'pv'}, {cls:'px70 ta-r',text:'净额BV',col:'bv'}], data:data.report});

def( 'dtvipsel', 'idatable', {id:'vipseldata', elem:'vipsel', tool:{cls:'tool', menu:[{id: 'pickvip', ico: {src: '{{ imgsurl }}/icos/tick.png'}, label: {txt: '选择'}, fn:function(){var ofo = jsonForm(dtvipsel.form);if(hop(ofo, 'guid')){
    setForm(data.optvips[isArray(ofo.guid)?ofo.guid[0]:ofo.guid], oaform.form, {name:['guid']}); try{iselect_pop.hide();}catch(e){} }}} ]},
    filter:{action:'/tiens/vip?opt=yes', col:{ vip_name:'', vipid:'' }},
    title:[{cls:'px70',text:'姓名',col:'vip_name'},{cls:'px140',text:'身份证号码',col:'vipid'}], fn:function(){ext(data.optguid, osort$(data.optvips, 'guid'));}, data:data.optvips});
def( 'dtpopvipsel', 'idatable', {id:'popvipseldata', elem:'popvipsel', tool:{cls:'tool', menu:[{id: 'pickvip', ico: {src: '{{ imgsurl }}/icos/tick.png'}, label: {txt: '选择'}, fn:function(){var ofo = jsonForm(dtpopvipsel.form);if(hop(ofo, 'guid')){
    setForm(data.optvips[isArray(ofo.guid)?ofo.guid[0]:ofo.guid], popform.form, {name:['guid']}); try{iselect_pop.hide();}catch(e){} }}} ]},
    filter:{action:'/tiens/vip?opt=yes', col:{ vip_name:'', vipid:'' }},
    title:[{cls:'px70',text:'姓名',col:'vip_name'},{cls:'px140',text:'身份证号码',col:'vipid'}], fn:function(){ext(data.optguid, osort$(data.optvips, 'guid'));}, data:data.optvips});
def( 'dtprodsel', 'idatable', {id:'prodseldata', elem:'prodsel', tool:{cls:'tool', menu:[{id: 'pickprod', ico: {src: '{{ imgsurl }}/icos/tick.png'}, label: {txt: '选择'}, fn:function(){var ofo = jsonForm(dtprodsel.form);if(hop(ofo, 'guid')){
    setForm(data.optprods[isArray(ofo.guid)?ofo.guid[0]:ofo.guid], oaform.form, {name:['guid']}); try{iselect_pop.hide();}catch(e){} }}} ]},
    filter:{action:'/tiens/prods?opt=yes', col:{pcode:'',pvtypename:{type:'select', value:'all', text:'所有PVBV类型', opts:function(){return getopts(data.pvtype,'guid','ptname');}}}},
    title:[{cls:'px80',text:'编码',col:'pcode'},{cls:'px220',text:'名称',col:'pname'}, {cls:'px30 ta-c',text:'单位',col:'unit'}, {cls:'px50 ta-r',text:'单价',col:'price'}, {cls:'px200',text:'PVBV类型',col:'pvtypename'}], fn:function(){ext(data.optguid, osort$(data.optprods, 'guid'));}, data:data.optprods});
def( 'dtpoprodsel', 'idatable', {id:'poprodseldata', elem:'poprodsel', tool:{cls:'tool', menu:[{id: 'pickpoprod', ico: {src: '{{ imgsurl }}/icos/tick.png'}, label: {txt: '选择'}, fn:function(){var ofo = jsonForm(dtpoprodsel.form);if(hop(ofo, 'guid')){
    setForm(data.optprods[isArray(ofo.guid)?ofo.guid[0]:ofo.guid], popform.form, {name:['guid']}); try{iselect_pop.hide();}catch(e){} }}} ]},
    filter:{action:'/tiens/prods?opt=yes', col:{pcode:'',pvtypename:{type:'select', value:'all', text:'所有PVBV类型', opts:function(){return getopts(data.pvtype,'guid','ptname');}}}},
    title:[{cls:'px80',text:'编码',col:'pcode'},{cls:'px220',text:'名称',col:'pname'}, {cls:'px30 ta-c',text:'单位',col:'unit'}, {cls:'px50 ta-r',text:'单价',col:'price'}, {cls:'px200',text:'PVBV类型',col:'pvtypename'}], fn:function(){ext(data.optguid, osort$(data.optprods, 'guid'));}, data:data.optprods});

function getabdata(skey, odt, elmid){ if(!data[skey]){ data[skey]={}; odt.data=data[skey]; } try{odt.submit();}catch(e){} return $(elmid);}
def('oaitab', 'itab', {id: 'oatab', elem: 'navi', target:'cont', ttl:9900, tabs: {
    sales: { id: 'oasale', tab: { label:'销售单' }, locked:1, ico: {src: '{{ imgsurl }}/icos/money.png'}, data: function(){ return getabdata('ssbill',dtssbill,'salemanage'); } },
    pvs: { id: 'oapvs', tab: { label:'业绩明细' }, locked:1, ico: {src: '{{ imgsurl }}/icos/page_white_text.png'}, data: function(){ return getabdata('cspvs',dtcspv,'pvsmanage');} },
    report: { id: 'oareport', tab: { label:'报单列表' }, locked:1, ico: {src: '{{ imgsurl }}/icos/report.png'}, data: function(){ return getabdata('report',dtrpt,'rptmanage'); } },
    vip: { id: 'oavip', tab: { label:'顾客/业务员' }, locked:1, ico: {src: '{{ imgsurl }}/icos/vcard.png'}, data: function(){ return getabdata('vips',dtvip,'vipmanage'); } },
    tsgz: { id: 'oatsgz', tab: { label:'促销-通知-断货' }, locked:1, ico: {src: '{{ imgsurl }}/icos/page_world.png'}, data: function(){ $('stockgz').innerHTML='<div style="margin:20px auto;text-align:center;"><div class="iloading"><div class="ianim"></div></div></div>'; var gz = aja$({url:'/tsgz', method:'get'},{finish:function(a){$('stockgz').innerHTML=a;}}); return $('stockgz'); } },
    info: { id: 'oainfo', rtl:1, notab:1, data:'{{ userinfo|safe }}' }
    } });
{% endblock %}